{"ast":null,"code":"import _regeneratorRuntime from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/regeneratorRuntime.js\";import _asyncToGenerator from\"/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/@babel/runtime/helpers/esm/asyncToGenerator.js\";import axios from'axios';import{baseUrl,exceptionUrl,refreshToken}from'../routes';import{store}from'../index';var apiClient=axios.create({withCredentials:false,// к каждому запросу cookie цепляются автоматически\nbaseURL:baseUrl()});apiClient.interceptors.request.use(function(config){var _config$url;if((_config$url=config.url)!==null&&_config$url!==void 0&&_config$url.includes(exceptionUrl())){return config;}// @ts-ignore\nconfig.headers.Authorization=\"Bearer \".concat(localStorage.getItem(\"\".concat(process.env.REACT_APP_NAME_TOKEN)));return config;});apiClient.interceptors.response.use(function(config){return config;},/*#__PURE__*/function(){var _ref=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(error){var originalRequest,response;return _regeneratorRuntime().wrap(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:originalRequest=error.config;if(!(error.response.status===401&&error.config&&!originalRequest._isRetry)){_context.next=14;break;}originalRequest._isRetry=true;_context.prev=3;_context.next=6;return axios.post(refreshToken(),{\"refresh_token\":localStorage.getItem(\"\".concat(process.env.REACT_APP_NAME_REFRESH_TOKEN))});case 6:response=_context.sent;store.setTokensTolLocalStorage(response);return _context.abrupt(\"return\",apiClient.request(originalRequest));case 11:_context.prev=11;_context.t0=_context[\"catch\"](3);store.logout();case 14:throw error;case 15:case\"end\":return _context.stop();}}},_callee,null,[[3,11]]);}));return function(_x){return _ref.apply(this,arguments);};}());export default apiClient;","map":{"version":3,"names":["axios","baseUrl","exceptionUrl","refreshToken","store","apiClient","create","withCredentials","baseURL","interceptors","request","use","config","url","includes","headers","Authorization","localStorage","getItem","process","env","REACT_APP_NAME_TOKEN","response","error","originalRequest","status","_isRetry","post","REACT_APP_NAME_REFRESH_TOKEN","setTokensTolLocalStorage","logout"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/src/http/index.ts"],"sourcesContent":["import axios from 'axios';\nimport {baseUrl, exceptionUrl, refreshToken} from '../routes';\nimport {AuthResponse} from \"../models/response/AuthResponse\";\nimport {store} from '../index'\n\nconst apiClient = axios.create({\n    withCredentials: false, // к каждому запросу cookie цепляются автоматически\n    baseURL: baseUrl()\n});\n\napiClient.interceptors.request.use((config) => {\n    if (config.url?.includes(exceptionUrl())) {\n        return config;\n    }\n    // @ts-ignore\n    config.headers.Authorization = `Bearer ${localStorage.getItem(`${process.env.REACT_APP_NAME_TOKEN}`)}`;\n    return config;\n});\n\napiClient.interceptors.response.use((config) => {\n    return config;\n}, async (error) => {\n    const originalRequest = error.config;\n\n    if (\n        error.response.status === 401 &&\n        error.config &&\n        !originalRequest._isRetry\n    ) {\n        originalRequest._isRetry = true;\n        try {\n            const response = await axios.post<AuthResponse>(refreshToken(),\n                {\"refresh_token\": localStorage.getItem(`${process.env.REACT_APP_NAME_REFRESH_TOKEN}`)}\n            );\n            store.setTokensTolLocalStorage(response);\n\n            return apiClient.request(originalRequest);\n        } catch (e) {\n            store.logout();\n        }\n    }\n    throw error;\n});\n\nexport default apiClient;"],"mappings":"4SAAA,MAAOA,MAAK,KAAM,OAAO,CACzB,OAAQC,OAAO,CAAEC,YAAY,CAAEC,YAAY,KAAO,WAAW,CAE7D,OAAQC,KAAK,KAAO,UAAU,CAE9B,GAAMC,UAAS,CAAGL,KAAK,CAACM,MAAM,CAAC,CAC3BC,eAAe,CAAE,KAAK,CAAE;AACxBC,OAAO,CAAEP,OAAO,EACpB,CAAC,CAAC,CAEFI,SAAS,CAACI,YAAY,CAACC,OAAO,CAACC,GAAG,CAAC,SAACC,MAAM,CAAK,iBAC3C,gBAAIA,MAAM,CAACC,GAAG,gCAAV,YAAYC,QAAQ,CAACZ,YAAY,EAAE,CAAC,CAAE,CACtC,MAAOU,OAAM,CACjB,CACA;AACAA,MAAM,CAACG,OAAO,CAACC,aAAa,kBAAaC,YAA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